<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {}
        // obj.a = 100
        // console.log(obj.a);
        // obj.a = 200
        // console.log(obj.a);
        var val = 100
        Object.defineProperty(obj, 'a', {
            get () {
                console.log('只要有人访问我是知道的');
                return val
            },
            set (newVal) {
                console.log('只要有人修改我是知道的');
                val = newVal
            }
        })
        console.log(obj.a);
        obj.a = 300
        console.log(obj.a);

    </script>
</body>

</html>